﻿// <copyright file="RadioTelegram.cs" company="Hallvard Korsgaard">
//  Microsoft Public License (Ms-PL). See license details here: http://enoceannet.codeplex.com/license
// </copyright>
// <author>Hallvard Korsgaard</author> 

namespace EnOcean.Radio
{
  using System;

  /// <summary>
  /// Base class for telegrams that are sent or received using the EnOcean radio protocol.
  /// </summary>
  [Serializable]
  public abstract class RadioTelegram : Telegram
  {
    /// <summary>
    /// Variable for the RepeatCounter property.
    /// </summary>
    private byte repeatCounter;

    /// <summary>
    /// Initializes a new instance of the RadioTelegram class.
    /// </summary>
    public RadioTelegram()
    {
      this.TelegramType = EnOcean.TelegramType.TransmitRadioTelegram;
    }

    /// <summary>
    /// Gets or sets the repeater level. The value 0 means this is the original message (not repeated).
    /// </summary>
    public byte RepeatCounter
    {
      get
      {
        return this.repeatCounter;
      }
      
      set
      {
        if (value >= 0x0 && value <= 0xf)
        {
          this.repeatCounter = value;
        }
        else
        {
          throw new ArgumentOutOfRangeException("RepeatCounter", "must be a 4 bit value in the range 0x0 to 0xf inclusive");
        }
      }
    }
  }
}
